package com.ruoyi.web.controller.lucky;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lucky.domain.TNotice;
import com.ruoyi.lucky.service.ITNoticeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公告信息Controller
 * 
 * @author ruoyi
 * @date 2020-11-12
 */
@Controller
@RequestMapping("/lucky/notice")
public class TNoticeController extends BaseController
{
    private String prefix = "lucky/notice";

    @Autowired
    private ITNoticeService tNoticeService;

    @RequiresPermissions("lucky:notice:view")
    @GetMapping()
    public String notice()
    {
        return prefix + "/notice";
    }

    /**
     * 查询公告信息列表
     */
    @RequiresPermissions("lucky:notice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TNotice tNotice)
    {
        startPage();
        List<TNotice> list = tNoticeService.selectTNoticeList(tNotice);
        return getDataTable(list);
    }

    /**
     * 导出公告信息列表
     */
    @RequiresPermissions("lucky:notice:export")
    @Log(title = "公告信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TNotice tNotice)
    {
        List<TNotice> list = tNoticeService.selectTNoticeList(tNotice);
        ExcelUtil<TNotice> util = new ExcelUtil<TNotice>(TNotice.class);
        return util.exportExcel(list, "notice");
    }

    /**
     * 新增公告信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公告信息
     */
    @RequiresPermissions("lucky:notice:add")
    @Log(title = "公告信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TNotice tNotice)
    {
        return toAjax(tNoticeService.insertTNotice(tNotice));
    }

    /**
     * 修改公告信息
     */
    @GetMapping("/edit/{noticeId}")
    public String edit(@PathVariable("noticeId") Long noticeId, ModelMap mmap)
    {
        TNotice tNotice = tNoticeService.selectTNoticeById(noticeId);
        mmap.put("tNotice", tNotice);
        return prefix + "/edit";
    }

    /**
     * 修改保存公告信息
     */
    @RequiresPermissions("lucky:notice:edit")
    @Log(title = "公告信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TNotice tNotice)
    {
        return toAjax(tNoticeService.updateTNotice(tNotice));
    }

    /**
     * 删除公告信息
     */
    @RequiresPermissions("lucky:notice:remove")
    @Log(title = "公告信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tNoticeService.deleteTNoticeByIds(ids));
    }
}
